﻿/*********************************************************************
 * @file   FITKSeparatePlate.h
 * @brief  分离板件类，将PID相同且不连通的板分开
 * @author zhangjingxuan (hiter25@outlook.com)
 * @date   2024-12-18
 *********************************************************************/
#ifndef __FITKSEPARATEPLATE_H__
#define __FITKSEPARATEPLATE_H__
#include "FITK2DMeshToolsAPI.h"
#include "FITKAbstractSeparatePlate.h"
#include "OpenMesh/Core/Mesh/PolyMesh_ArrayKernelT.hh"
#include <QList>
#include <QVector>

namespace Interface
{
    /**
     * @brief  分离板件类，将PID相同且不连通的板分开
     * @author zhangjingxuan (hiter25@outlook.com)
     * @date   2024-12-18
     */
    class FITK2DMeshToolsAPI FITKSeparatePlate : public FITKAbstractSeparatePlate
    {
    public:
        /**
         * @brief  OpenMesh网格精度设置double
         * @author zhangjingxuan (hiter25@outlook.com)
         * @date   2024-12-27
         */
        struct PolyTraits : public OpenMesh::DefaultTraits
        {
            typedef OpenMesh::Vec3d Point;
            typedef OpenMesh::Vec3d Normal;
        };
        typedef OpenMesh::PolyMesh_ArrayKernelT<PolyTraits>  FITKPlateMesh;
    public:
        FITKSeparatePlate();
        ~FITKSeparatePlate();
        /**
         * @brief    获取组成每块板的网格单元索引
         * @param[i] meshPoints 点数据
         * @param[i] meshFaces 面单元数据
         * @return   QList<QList<int>> 组成每一块板的网格单元id
         * @author   zhangjingxuan (hiter25@outlook.com)
         * @date     2024-12-18
         */
        QList<QList<int>> getPlates(const QList<Core::FITKNode*>& meshPoints, const QList<Interface::FITKAbstractElement*>& meshFaces) override;
    private:
        /**
         * @brief    初始化板网格数据
         * @param[i] meshPoints 点数据
         * @param[i] meshFaces 面单元数据
         * @return   bool ture 初始化成功,false 初始化失败
         * @author   zhangjingxuan (hiter25@outlook.com)
         * @date     2024-12-18
         */
        bool initPlatesMesh(const QList<Core::FITKNode*>& meshPoints, const QList<Interface::FITKAbstractElement*>& meshFaces);
        /**
         * @brief    获取分离的单块板
         * @param[i] usedFaced 已访问过的面
         * @param[i] plateFaces 存储一块板的所有面
         * @return   void
         * @author   zhangjingxuan (hiter25@outlook.com)
         * @date     2024-12-19
         */
        void SeparatePlate(QVector<bool>& usedFaced, QList<int>& plateFaces);
        /**
         * @brief    获取所有板及板组成的面
         * @return   QList<QList<OpenMesh::FaceHandle>> 所有板及板组成的面
         * @author   zhangjingxuan (hiter25@outlook.com)
         * @date     2024-12-19
         */
        QList<QList<int>> getPlatesFace();
    private:
        /**
         * @brief  OpenMesh网格对象
         * @author zhangjingxuan (hiter25@outlook.com)
         * @date   2024-12-18
         */
        FITKPlateMesh* m_mesh{ nullptr };
    };
}
#endif // !__FITKSEPARATEPLATE_H__